package com.hy.study.driver;

import com.hy.study.bean.SortFlowBean;
import com.hy.study.mapper.TopNMapper;
import com.hy.study.reduce.TopNReducer;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/**
 * @author huyong
 * @date 2024 年 02 月 07 日 16:00: 05
 */
public class TopNDriver {
    public static void main(String[] args) throws Exception {
        String inputfile = "F:\\study\\Hadoop\\output\\phone_result2";
        String outputfile = "F:\\study\\hadoop_wordcount\\output\\result6";
        Job job = Job.getInstance(new Configuration());

        job.setJarByClass(TopNDriver.class);

        job.setMapperClass(TopNMapper.class);
        job.setReducerClass(TopNReducer.class);

        job.setMapOutputKeyClass(SortFlowBean.class);
        job.setMapOutputValueClass(Text.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        FileInputFormat.addInputPath(job, new Path(inputfile));
        FileOutputFormat.setOutputPath(job, new Path(outputfile));

        boolean completion = job.waitForCompletion(true);
        System.exit(completion ? 1 : 0);
    }
}
